home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 80 / CD Actual 80 Julio-Agosto 2003.iso / Linux / LinuxGazette / lg / issue72 / misc / nielsen / modules / Misc.pm < prev    next >
Encoding:
Perl POD Document  |  2002-08-14  |  3.9 KB  |  163 lines

  1. #!/usr/bin/perl
  2.  
  3. #              Create Functions for Perl/PostgreSQL version 1.0
  4.  
  5. #                       Copyright 2001, Mark Nielsen
  6. #                            All rights reserved.
  7. #    This Copyright notice was copied and modified from the Perl 
  8. #    Copyright notice. 
  9. #    This program is free software; you can redistribute it and/or modify
  10. #    it under the terms of either:
  11.  
  12. #        a) the GNU General Public License as published by the Free
  13. #        Software Foundation; either version 1, or (at your option) any
  14. #        later version, or
  15.  
  16. #        b) the "Artistic License" which comes with this Kit.
  17.  
  18. #    This program is distributed in the hope that it will be useful,
  19. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See either
  21. #    the GNU General Public License or the Artistic License for more details.
  22.  
  23. #    You should have received a copy of the Artistic License with this
  24. #    Kit, in the file named "Artistic".  If not, I'll be glad to provide one.
  25.  
  26. #    You should also have received a copy of the GNU General Public License
  27. #   along with this program in the file named "Copying". If not, write to the 
  28. #   Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 
  29. #    02111-1307, USA or visit their web page on the internet at
  30. #    http://www.gnu.org/copyleft/gpl.html.
  31.  
  32.  
  33. package SAMPLE::Misc;
  34.  
  35. use strict;
  36. use Apache;
  37. use DBI;
  38. use CGI;
  39. use Crypt::Blowfish;
  40. use SAMPLE::Constants;
  41.  
  42. my $Blowfish_Key = "ABC BLOWFISH KEY 123456789012345";
  43. my $Blowfish_Cipher = new Crypt::Blowfish $Blowfish_Key;
  44.  
  45. #-----------------------------------
  46. sub Encrypt
  47. {
  48.     my $self = shift;
  49.     my $String = shift;
  50.  
  51.     my $Temp = $String;
  52.     my $Encrypted = "";
  53.  
  54. while (length $Temp > 0)  
  55. {
  56.     while (length $Temp < 8) {$Temp .= "\t";}
  57.     my $Temp2 = $Blowfish_Cipher->encrypt(substr($Temp,0,8));
  58.     $Encrypted .= $Temp2; 
  59.     if (length $Temp > 8) {$Temp = substr($Temp,8);} else {$Temp = "";}
  60. }
  61.  
  62. my $Unpacked = unpack("H*",$Encrypted);
  63.  
  64. return ($Unpacked);
  65. }
  66.  
  67. #-------------------------------------------------------------------------
  68. sub Decrypt
  69. {
  70.     my $self = shift;
  71.     my $String = shift;
  72.  
  73.     my $Packed = pack("H*",$String);
  74.  
  75.     my $Temp = $Packed;
  76.     my $Decrypted = "";
  77. while (length $Temp > 0)  
  78. {
  79.     my $Temp2 = substr($Temp,0,8);
  80.   if (length $Temp2 == 8) 
  81.   {
  82.       my $Temp3 = $Blowfish_Cipher->decrypt($Temp2);
  83.       $Decrypted .= $Temp3;
  84.   } 
  85.     if (length $Temp > 8) {$Temp = substr($Temp,8);} else {$Temp = "";}
  86. }
  87. $Decrypted =~ s/\t+$//g;
  88.  
  89. return ($Decrypted);
  90. }
  91.  
  92. #-------------------------------------------
  93. sub Convert_Html
  94. {
  95.     my $self = shift;
  96.     my $String = shift;
  97.  
  98.     if (ref $String) {$String = "";}
  99. else 
  100. {
  101.     $String =~ s/\&/\&\;/g;
  102.     $String =~ s/\"/\"\;/g;
  103.     $String =~ s/\>/\>\;/g;
  104.     $String =~ s/\</\<\;/g;
  105.     $String =~ s/\|/\&\#124\;/g;
  106.  
  107. }
  108.  
  109. return ($String);
  110. }
  111.  
  112. #-------------------------------------------
  113. sub Clean_String
  114. {
  115.     my $self = shift;
  116.     my $String = shift;
  117.     my $No = shift;
  118.     if ($No > 0) {$String = substr($String,0,$No);}
  119.  
  120.     if (ref $String) {$String = "";}
  121. else 
  122. {
  123.  $String =~ s/[^a-zA-Z0-9 \~\!\@\#\$\%\^\&\*\(\)\_\+\-\=\\\[\]\;\'\,\.\/\{\}\:\"\<\>\?\n\|]//g;
  124.   }
  125. return ($String);
  126. }
  127.  
  128. #--------------------------------------------------------------------
  129.  
  130. sub File_Query
  131. {
  132. my $self = shift;
  133. my %Args = @_;
  134. if (!(exists $Args{'file'}))  {return (-1);}
  135.  
  136. my $File = $Args{'file'};
  137. my (@Temp) = split(/\./, $File);
  138. my $Ext = pop @Temp;
  139. if (!($Ext =~ /[a-z]/i)) {$Ext = "ext";}
  140.  
  141. my $Global = MAIL::Constants->Get_Constants;
  142. my $TempDir = $Global->{'tempdir'};
  143.  
  144. my $New = "$TempDir/1.$Ext";
  145. my $No = 1;
  146. while (-e $File) {$No++; $File = "$TempDir/$No.$Ext";} 
  147.  
  148. my $buffer;
  149. open (OUTFILE,">$New");
  150. while (my $bytesread=read($File,$buffer,1024)) {print OUTFILE $buffer;}
  151. close OUTFILE;
  152.  
  153. #if ($Ext eq ".wav")
  154. #  {
  155. #  my $Command = "cd $Data_Dir; /usr/local/realproducer-8.5/realproducer -i intro$Ext";
  156. #  system ($Command);
  157. #  }
  158.  
  159. return ($File);
  160. }
  161.  
  162.  
  163.